package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;

import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "护理项目相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {


    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("分页查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> pageQuery(
            @ApiParam(name = "name", value = "护理项目名称") String name,
            @ApiParam(name = "status", value = "状态 0禁用 1启用") Integer status,
            @ApiParam(name = "pageNum", value = "当前页")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(name = "pageSize", value = "每页条数")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> result = nursingProjectService.pageQuery(name, status, pageNum, pageSize);
        return ResponseResult.success(result);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.addNursingProject(nursingProjectDTO);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult getNursingProjectById(
            @ApiParam(name = "id", value = "护理项目id", required = true)
            @PathVariable Long id) {
        NursingProjectVo vo = nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(vo);
    }

    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult update(
            @ApiParam(value = "修改护理项目数据", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(
            @ApiParam(name = "id", value = "护理项目id", required = true)
            @PathVariable Long id) {
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(name = "id", value = "护理项目id", required = true)
            @PathVariable Long id,
            @ApiParam(name = "status", value = "护理项目状态", required = true)
            @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult getAllNursingProject() {
        List<NursingProjectVo> vos = nursingProjectService.getAllNursingProject();
        return ResponseResult.success(vos);
    }
}
